# 限制对象添加属性
class Person:
    __slots__=['age','num', 'run'] # 这里的方法也是受这里的限制的
    pass
    def www():
        pass

p1 = Person()

p1.age = 1
p1.num = 2

print(p1.age)
print(p1.num)

p2 = Person()

p2.age = 9
# p2.num = 6
print(
    p2.age,
    
)

def run():
    pass
p2.run = run

p2.a = 'a'
print(p2.a)

# Traceback (most recent call last):
#   File "C:\Users\wyl350\Desktop\demo-python\ÃæÏò¶ÔÏó\class.py", line 23, in <module>
#     p2.a = 'a'
# AttributeError: 'Person' object has no attribute 'a'

